package com.waiter.moximoxi.adapter;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.waiter.moximoxi.R;
import com.waiter.moximoxi.bean.OrderInfoDiscountListBean;

import java.util.List;

/**
 * Created by 17639 on 2020/12/6.
 */

public class OrderInfoDiscountAdapter extends BaseQuickAdapter<OrderInfoDiscountListBean, BaseViewHolder> {

    public OrderInfoDiscountAdapter(int layout, List<OrderInfoDiscountListBean> itemList) {
        super(R.layout.item_order_info_discount, itemList);
    }

    public OnDiscountClickListener onDiscountClickListener;

    public void setOnDiscountClickListener(OnDiscountClickListener onDiscountClickListener) {
        this.onDiscountClickListener = onDiscountClickListener;
    }

    private int type;//是否可以点击

    public void setType(int type) {
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderInfoDiscountListBean item) {
        TextView discount_tv = helper.getView(R.id.discount_tv);
        LinearLayout item_order_info_discount_ll = helper.getView(R.id.item_order_info_discount_ll);

        discount_tv.setText(item.title);

        item_order_info_discount_ll.setBackground(item.isChecked ? mContext.getResources().getDrawable(R.drawable.shape_solid_isopen_5dp) :
                mContext.getResources().getDrawable(R.drawable.shape_stoke_white_5dp));

        //如果已经支付过就不可点
        helper.getConvertView().setEnabled(type == 1 ? false : true);


        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDiscountClickListener.discountClick(helper.getLayoutPosition());
            }
        });
    }

    public interface OnDiscountClickListener {
        void discountClick(int position);
    }
}
